package com.vencent.spring.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.ViewResolver;
import org.springframework.web.servlet.config.annotation.DefaultServletHandlerConfigurer;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
import org.springframework.web.servlet.view.InternalResourceViewResolver;

/**
 * spring提供的EnableWebMvc注解用来代替<mvc:annotation-driven/>
 * includeFilters 是在基础包的条件下进一步帅选的， 所以必须加basePackages来约束基础包，如果不指定就默认从本类所在包下查找, 
 * 且 必须要加useDefaultFilters=false， 默认为true，代表自动扫描获取基础包下的全部@Controller,@Component, @Service.
 * excludeFilters 是在基础包的条件下进一步帅选的， 所以必须加basePackages来约束基础包，但是别加useDefaultFilters=false.
 * @author wbw
 *
 */
@EnableWebMvc
@Configuration
@ComponentScan(basePackages={"com.vencent.spring.web", "com.vencent.spring.handle"})
public class WebConfig extends WebMvcConfigurerAdapter{
	@Bean
	public ViewResolver viewResolver(){
		InternalResourceViewResolver resolver = new InternalResourceViewResolver();
		resolver.setPrefix("/WEB-INF/views/");
		resolver.setSuffix(".jsp");
		resolver.setExposeContextBeansAsAttributes(true);
		return resolver;
	}
	
	@Override
	public void configureDefaultServletHandling(DefaultServletHandlerConfigurer configurer) {
		configurer.enable();
	}
}
